// components/index-item/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item: {
      type: Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },
  lifetimes: {
    attached() {
      this.video = wx.createVideoContext("video" + this.data.item.topicType, this);
    }
  },
  //添加判断划出屏幕就不播放
  ready: function () {
    this.createIntersectionObserver().relativeToViewport().observe("#" + "video" + this.data.item.topicType, (res) => {
      if (res.intersectionRatio > 0 && this.data.attr.autoPlay) {
        this.video.play()
      } else {
        this.video.pause()
      }
    })
  },
  /**
   * 组件的方法列表
   */
  methods: {
    //图片预览
    viewImage(ev) {
      wx.previewImage({
        urls: ev.mark.urls,
        current: ev.mark.urls[ev.target.dataset.index]
      })
    },
    //播放视频
    play(ev) {
      this.triggerEvent("updatePlayId", {
        id: ev.mark.id,
        _this: this
      })
    },
    //去话题
    toSubject(ev) {
      wx.navigateTo({
        url: `/pkgPublish/pages/subject/index?topicType=${ev.mark.topicType}`,
      })
    },
  }
})